<%--
  Created by IntelliJ IDEA.
  User: ZHouZHiZHao
  Date: 2021/7/13
  Time: 9:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@include file="../common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/page.css">

    <title> <spring:message code="class.page.title"/></title>

    <script type="text/javascript">
        var _gridWidth;
        var _gridHeight;
        //页面自适应
        function resizePageSize(){
            _gridWidth = $(document).width()-12;/*  -189 是去掉左侧 菜单的宽度，   -12 是防止浏览器缩小页面 出现滚动条 恢复页面时  折行的问题 */
            _gridHeight = $(document).height()-32-80; /* -32 顶部主菜单高度，   -90 查询条件高度*/
        }

        $(function()
        {
            resizePageSize();
            var _columnWidth= (_gridWidth-150)/4;
            $("#flexiGridID").flexigrid({
                width : _gridWidth,
                height : _gridHeight,
                url : "${pageContext.request.contextPath}/sto/getSharedFileslist",
                dataType : 'json',
                colModel : [
                    {display : "<spring:message code='file.name'/>",name : 'fileName',width : _columnWidth, sortable : false,align : 'center'},
                    {display : "<spring:message code='file.content.length'/>",name : 'fileLength',width : _columnWidth, sortable : false,align : 'center'},
                    {display : "<spring:message code='file.modify.time'/>",name : 'fileLastTime',width : _columnWidth, sortable : false,align : 'center'},
                    {display : "<spring:message code='file.operation'/>",name : 'fileName',width : _columnWidth, sortable : true,align : 'center',process: function(v,_trid,_row)
                        {
                            var htmlContents1 ='<a style="color:blue;cursor:pointer;" href="#" onclick="cancelSharing(\''+_row.id+'\');"><spring:message code="file.cancel.sharing"/></a>';
                            var htmlContents2 ='<a style="color:blue;cursor:pointer;" href="#" onclick="shareFile(\''+_row.fileName+'\');"><spring:message code="file.share"/></a>';

                            return htmlContents1+"|"+htmlContents2;

                        }}

                ],
                resizable : false, //resizable table是否可伸缩
                useRp : true,
                usepager : false, //是否分页
                autoload : false, //自动加载，即第一次发起ajax请求
                hideOnSubmit : true, //是否在回调时显示遮盖
                showcheckbox : true, //是否显示多选框
                //rowhandler : rowDbclick, //是否启用行的扩展事情功能,在生成行时绑定事件，如双击，右键等
                rowbinddata : true,
                numCheckBoxTitle : "<spring:message code='common.selectall'/>"
            });
            query();

            $("#share-tips-diags-id").dialog(
                {
                    autoOpen : false,
                    width : 400,
                    height : 300,
                    modal : true,
                    resizable : false,
                    title: "<spring:message code='file.add'/>",
                    buttons: [
                        {
                            text: "<spring:message code='common.confirm'/>",
                            click: function() {
                                $( this ).dialog( "close" );

                            }
                        }
                    ]
                }
            );

        });

        function query(param1){
            $('#flexiGridID').flexOptions({
                newp: 1,
                extParam: param1||[]
            }).flexReload();
        }

        function cancelSharing(id) {
            console.log("id="+id);
            console.log();
            $.ajax({
                type : 'POST',
                url : '${pageContext.request.contextPath}/sto/cancelSharing/'+id+'',
                dataType : 'json',
                cache : false,
                data : {},
                success : function() {
                    message("取消分享成功！")
                    $("#flexiGridID").flexReload();
                },
                error : function() {
                    message("<spring:message code='common.error'/>");
                },
            });
        }

        function shareFile(file_name) {
            console.log("file_name="+file_name);
            console.log();
            $.ajax({
                type : 'POST',
                url : '${pageContext.request.contextPath}/file/share/'+file_name+'',
                dataType : 'json',
                cache : false,
                data : {},
                success : function(data) {
                    $("#share-tips-id").val(data.msg);
                    $("#share-tips-diags-id").dialog("open");
                    $("#flexiGridID").flexReload();
                },
                error : function() {
                    message("<spring:message code='common.error'/>");
                },
            });
        }

    </script>

</head>
    <body>
        <div style="padding-top: 5px;">
        </div>

        <table id="flexiGridID" style="display: block;margin: 0px;"></table>\

        <div id="share-tips-diags-id" style="display: none">
           <textarea id="share-tips-id" rows="4" cols="10" style="width: 367px;height: 134px"></textarea>
        </div>
    </body>
</html>